package com.sgb.goods.view.fragment.manage;

import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayoutMediator;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsFragmentManageListRightBinding;
import com.sgb.goods.utils.base.adapter.BasePagerAdapter;
import com.sgb.goods.utils.base.fragment.BaseFragment;
import com.sgb.goods.viewmodel.GoodsManageListRightViewModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品管理-商品管理列表界面(页面二)
 * @author cyj
 */
public class GoodsManageListRightFragment extends BaseFragment<GoodsFragmentManageListRightBinding, GoodsManageListRightViewModel> {

    /** 卡片名称 */
    private final String[][] typeArray = {{"已上架", "1"}, {"已下架", "2"}};

    /** 创建fragment */
    protected List<Fragment> getFragments() {
        List<Fragment> fragments = new ArrayList<>();
        for (String[] params : typeArray) {
            fragments.add(new GoodsManageListOperationFragment(params[1]));
        }
        return fragments;
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.goods_fragment_manage_list_right;
    }

    @Override
    protected void initViewModel() {
        mViewModel = createViewModel(GoodsManageListRightViewModel.class, BR.viewModel);
    }

    @Override
    public void lazyLoadData() {
        List<Fragment> list = getFragments();
        BasePagerAdapter<Fragment> adapter = new BasePagerAdapter<>(this);
        mDataBinding.vpView.setAdapter(adapter);
        mDataBinding.vpView.setOffscreenPageLimit(list.size());
        new TabLayoutMediator(mDataBinding.tabGroup, mDataBinding.vpView, (tab, position) ->
                tab.setText(typeArray[position][0])).attach();
        adapter.setDataList(list);
    }

    @Override
    protected void initObserve() {

    }

    @Override
    protected void initListener() {

    }

}